import 'package:flutter/material.dart';
import 'package:hook_up_rent/utils/index.dart';
import 'package:hook_up_rent/widgets/common_floating_action_button.dart';
import 'package:hook_up_rent/widgets/common_form_radio.dart';
import 'package:hook_up_rent/widgets/common_form_select.dart';

import 'modal.dart';

double commonPadding = 10.0;

class RoomAddPage extends StatefulWidget {

  @override
  _RoomAddPageState createState() => _RoomAddPageState();
}

class _RoomAddPageState extends State<RoomAddPage> {

  int rentType = 0;
  int decorationType = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("房源发布"),
        centerTitle: true,
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
      floatingActionButton: CommonFloatingActionButton("发布", () {
        print("提交");
      }),
      body: ListView(
        children: [
          _buildRoomAddTitle("房源信息"),
          _buildRoomAddSelect(context,"小区","请选择小区",Icon(Icons.keyboard_arrow_right)),
          _buildRoomAddInput(context, "租金", "请输入租金", Text("元/月")),
          _buildRoomAddInput(context, "大小", "请输入房屋大小", Text("平方米")),
          CommonFormRadio(value: rentType,options: ["合租","整租"],label: "租赁方式",onChange: (index){
            setState(() {
              rentType = index;
            });
          },),
          CommonFormRadio(value: decorationType,options: ["精装","简装"],label: "装修",onChange: (index){
            setState(() {
              decorationType = index;
            });
          },),
          CommonFormSelect(label: "户型",value: 0,options: HouseType,onChange: (val){},),
          CommonFormSelect(label: "楼层",value: 0,options: Floor,onChange: (val){},),
          CommonFormSelect(label: "朝向",value: 0,options: OrientationType,onChange: (val){},)
        ],
      ),
    );
  }

  _buildRoomAddTitle(String title) {
    return Container(
      padding: EdgeInsets.only(top: commonPadding, left: commonPadding),
      child: Text(
        title,
        style: TextStyle(fontSize: 20, fontWeight: FontWeight.w800),
      ),
    );
  }

  _buildRoomAddSelect(BuildContext context,String label,String hintText, Widget suffix){
    return Container(
      padding: EdgeInsets.all(commonPadding),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  width: 1.0, color: Theme.of(context).dividerColor))),
      child: GestureDetector(
        onTap: (){
          Navigator.of(context).pushNamed("404");
        },
        child:Row(
        children: [
          Container(
            width: 100.0,
            child: Text(
              label,
              style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w600),
            ),
          ),
          Expanded(
            child:Text(hintText,style: TextStyle(color:ColorsUtil.hexColor(0xaeacae),fontSize:16.0)),
          ),
          suffix
        ],
      ),
      )
      
    );
  }

  _buildRoomAddInput(
      BuildContext context, String label, String hintText, Widget suffix) {
    return Container(
      padding: EdgeInsets.only(left: commonPadding, right: commonPadding),
      decoration: BoxDecoration(
          border: Border(
              bottom: BorderSide(
                  width: 1.0, color: Theme.of(context).dividerColor))),
      child: Row(
        children: [
          Container(
            width: 100.0,
            child: Text(
              label,
              style: TextStyle(fontSize: 16.0, fontWeight: FontWeight.w600),
            ),
          ),
          Expanded(
            child: TextField(
              decoration:
                  InputDecoration(hintText: hintText, border: InputBorder.none),
            ),
          ),
          suffix
        ],
      ),
    );
  }
}
